package pmr.core.finder;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.search.MethodReferenceMatch;
import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.core.search.SearchRequestor;
import org.eclipse.jdt.internal.core.SourceField;

public class PMRSimpleSearchRequestor extends SearchRequestor {

	private final UnusedMethodsRepository repository;

	private final IMethod searchedMethod;

	public PMRSimpleSearchRequestor(UnusedMethodsRepository repository,
			IMethod method) {
		this.repository = repository;
		this.searchedMethod = method;
	}

	@Override
	public void acceptSearchMatch(final SearchMatch match) throws CoreException {
		if (!(match instanceof MethodReferenceMatch))
			return;
		if (match.getElement() instanceof SourceField)
			return;
		repository.remove(searchedMethod);

	}

}
